using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using System.Linq;

using NHibernate.Mapping;



namespace App.Persistencia
{
    internal class FabricaSesiones
    {
        private static FabricaSesiones _session = null;
        private Configuration _nhConfiguration;
        private ISessionFactory _sessionFactory;

        public Configuration Cfg
        {
            get { return _nhConfiguration; }
        }

        protected FabricaSesiones()
		{
            _nhConfiguration = PersistenciaConfig.DefaultConfiguration;
            
           _sessionFactory = _nhConfiguration.BuildSessionFactory();
        }

        public static FabricaSesiones Instance
        {
            get
            {
                if (_session == null)
                    _session = new FabricaSesiones();

                return _session;
            }
        }

        public ISession GetSession()
        {
            
            return _sessionFactory.OpenSession();
        }

        public ISessionFactory GetSessionFactory()
        {
            return _sessionFactory;
        }

        public ISession GetSession(IInterceptor interceptor)
        {
            return _sessionFactory.OpenSession(interceptor);
        }

        public ISessionFactory GetNHibernateFactory()
        {
            return _sessionFactory;
        }
    }
}
